﻿using ViewMaker.Core.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using ViewMaker.Core;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;

namespace ViewMaker.Core.Tests
{
    [TestClass()]
    public class ListBoxViewControlTest
    {
        [TestMethod()]
        public void 標準的なListBoxのXAML生成()
        {
            var target = new ListBoxViewControl { Item = new ViewLayoutItem { Name = "cb001", Caption = "リストボックス", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<ListBox>(xaml);
            Assert.AreEqual("cb001", actual.Name);
            Assert.AreEqual("currentValue", actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Path.Path);
            Assert.AreEqual("dataSource", actual.GetBindingExpression(ListBox.ItemsSourceProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(ListBox.SelectedItemProperty).ParentBinding.Mode);
        }


        [TestMethod()]
        public void 値表示カラム指定なListBoxのXAML生成()
        {
            var target = new ListBoxViewControl { Item = new ViewLayoutItem { Name = "cb001", Caption = "リストボックス", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            target.DisplayMemberPath = "display";
            target.SelectedValuePath = "valuePath";
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<ListBox>(xaml);
            Assert.AreEqual("cb001", actual.Name);
            Assert.AreEqual("currentValue", actual.GetBindingExpression(ListBox.SelectedValueProperty).ParentBinding.Path.Path);
            Assert.AreEqual("dataSource", actual.GetBindingExpression(ListBox.ItemsSourceProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(ListBox.SelectedValueProperty).ParentBinding.Mode);
            Assert.AreEqual("display", actual.DisplayMemberPath);
            Assert.AreEqual("valuePath", actual.SelectedValuePath);
        }

        [TestMethod()]
        public void アイテム指定なListBoxのXAML生成()
        {
            var target = new ListBoxViewControl { Item = new ViewLayoutItem { Name = "cb001", Caption = "リストボックス", BindPath = "currentValue" } };
            target.Items = new string[] { "ONE", "TWO", "THREE" };
            var xaml = target.CreateXaml(TestHelper.CreateTestParent())[1];

            var actual = TestHelper.GetFrameworkElement<ListBox>(xaml);
            Assert.AreEqual("cb001", actual.Name);
            Assert.AreEqual("currentValue", actual.GetBindingExpression(ComboBox.SelectedItemProperty).ParentBinding.Path.Path);
            Assert.AreEqual(BindingMode.TwoWay, actual.GetBindingExpression(ComboBox.SelectedItemProperty).ParentBinding.Mode);
            Assert.AreEqual("ONE", (string)actual.Items[0]);
            Assert.AreEqual("THREE", (string)actual.Items[2]);

        }

        [TestMethod()]
        public void ListBoxViewControlの編集画面が表示可能()
        {
            var target = new ListBoxViewControl { Item = new ViewLayoutItem { Name = "cb001", Caption = "リストボックス", BindPath = "currentValue" } };
            target.ItemsSource = "dataSource";
            var baml = ViewUtil.BuildContent(target);
            Assert.IsNotNull(baml);
        }

    }
}
